List Filtering

In this kata you will create a function that takes a list of non-negative integers and strings and returns a new list with the strings filtered out.

Example

filter_list([1,2,'a','b']) == [1,2]
filter_list([1,'a','b',0,15]) == [1,0,15]
filter_list([1,2,'aasf','1','123',123]) == [1,2,123]

In [12]:
def filter_list(l):
  'return a new list with the strings filtered out'
  return [i for i in l if isinstance(i, int)]

In [13]:
assert(filter_list([1,2,'a','b']) == [1,2])
assert(filter_list([1,2,'aasf','1','123',123]) == [1,2,123])

In [14]:
filter_list([1,2,'aasf','1','123',123])


Out[14]:
[1, 2, 123]

In [28]:
l = [1, 2, 10, 5]
l.sort()
print l


[1, 2, 5, 10]

Sum Two Smallest

Forgot the full instructions, but basically just sum the two smallests values in an unsorted array of unsigned ints


In [41]:
from functools import reduce

def sum_two_smallest_numbers(numbers):
    #your code here
    numbers.sort()
    return reduce(lambda x,y: x+y, numbers[:2])

In [42]:
sum_two_smallest_numbers([19,5,42,2,77])


Out[42]:
7

In [ ]: